package com.jiuan.transfer.mqtt.domain;
import java.io.FileInputStream;
import java.util.Properties;
/**
 * Created by Administrator on 2017/1/4.
 */
public class Config {
    private static String configFile="./mqtt_rabbit_redis.conf";
    private static String configFile_win="D:\\mqtt_rabbit_redis.conf";


    public static void initConfig(String config) {
        if(null!=config && !config.equals("")){
            configFile=config;
        }else{
            String osName = System.getProperties().getProperty("os.name"); //操作系统名称
            if(osName.contains("Windows")){
                configFile=configFile_win;
            }
        }
        System.out.println("init config..."+configFile);
        Properties propertie = new Properties();
        try {
            FileInputStream inputFile = new FileInputStream(configFile);
            propertie.load(inputFile);

            //rabbit
            rabbit_ip = propertie.getProperty("rabbit_ip");
            rabbit_port = Integer.valueOf(propertie.getProperty("rabbit_port"));
            rabbit_username= propertie.getProperty("rabbit_username");
            rabbit_password=propertie.getProperty("rabbit_password");
            rabbit_connection_number=Integer.valueOf(propertie.getProperty("rabbit_connection_number"));
            rabbit_queue=propertie.getProperty("rabbit_queue");

            //redis
            redis_ips=propertie.getProperty("redis_ips");
            redis_ip=propertie.getProperty("redis_ip");
            redis_port=Integer.valueOf(propertie.getProperty("redis_port"));
            redis_timeout=Integer.valueOf(propertie.getProperty("redis_timeout"));

            //mqtt
            mqtt_port=Integer.valueOf(propertie.getProperty("mqtt_port"));
            mqtt_clientid_prefix=propertie.getProperty("mqtt_clientid_prefix");
            mqtt_keepalive=Short.valueOf(propertie.getProperty("mqtt_keepalive"));


            inputFile.close();
            System.out.println("config OK !");
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("cannot find configur file, system exit!");
            System.exit(0);
        }

    }


    private static String redis_ips="192.168.12.191:6379,192.168.12.191:6380,192.168.12.191:6381,192.168.12.191:6382,192.168.12.191:6383,192.168.12.191:6384";



    private static String rabbit_ip;



    private static Integer rabbit_port;



    private static String rabbit_password;



    private static String rabbit_username;



    private static Integer rabbit_connection_number;



    private static String rabbit_queue;



    private static String redis_ip;



    private static Integer redis_port;



    private static Integer redis_timeout;



    private static Integer mqtt_port;



    private static String mqtt_clientid_prefix;



    private static Short mqtt_keepalive;



    /**
     * @return the configFile
     */
    public static String getConfigFile() {
        return configFile;
    }



    /**
     * @return the redis_ips
     */
    public static String getRedis_ips() {
        return redis_ips;
    }



    /**
     * @return the rabbit_ip
     */
    public static String getRabbit_ip() {
        return rabbit_ip;
    }



    /**
     * @return the rabbit_port
     */
    public static Integer getRabbit_port() {
        return rabbit_port;
    }



    /**
     * @return the rabbit_password
     */
    public static String getRabbit_password() {
        return rabbit_password;
    }



    /**
     * @return the rabbit_username
     */
    public static String getRabbit_username() {
        return rabbit_username;
    }



    /**
     * @return the rabbit_connection_number
     */
    public static Integer getRabbit_connection_number() {
        return rabbit_connection_number;
    }



    /**
     * @return the rabbit_queue
     */
    public static String getRabbit_queue() {
        return rabbit_queue;
    }



    /**
     * @return the redis_ip
     */
    public static String getRedis_ip() {
        return redis_ip;
    }



    /**
     * @return the redis_port
     */
    public static Integer getRedis_port() {
        return redis_port;
    }



    /**
     * @return the redis_timeout
     */
    public static Integer getRedis_timeout() {
        return redis_timeout;
    }



    /**
     * @return the mqtt_port
     */
    public static Integer getMqtt_port() {
        return mqtt_port;
    }



    /**
     * @return the clientid
     */
    public static String getMqtt_clientid_prefix() {
        return mqtt_clientid_prefix;
    }



    /**
     * @return the keepalive
     */
    public static Short getMqtt_keepalive() {
        return mqtt_keepalive;
    }



}
